package edu.pku.sei.act.ctrl.command;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.act.model.mote.Mote;
import edu.pku.sei.act.model.mote.Radio;
import edu.pku.sei.gmp.model.concept.GMPModelElement;

public class CreateRadioCommand extends Command{

	private Mote model;
	private Radio radio;
	
	public CreateRadioCommand(GMPModelElement parent, Radio radio ) {
		super("Create Radio");
		this.model = (Mote)parent;
		this.radio = radio;
	}
	
	public boolean canExecute() {
		return model !=null && radio != null ;
	}
	
	public void execute() {
		if (model != null) {
			radio.setContainer(model);
			//model.getRootElements().add(radio);
			model.setRadio(radio);
		}
	}
	
	public void undo() {
		if (model != null) {
			//model.getRootElements().remove(radio);
			model.setRadio(null);
		}
		radio.setContainer(null);
	}
	
	public void redo(){
		this.execute();
	}
	
}
